import AutoChart from '@/components/Echarts/AutoChart';
import { articleHomePage } from '@/services/api';
// @ts-ignore
import { BorderBox4, BorderBox7 } from '@jiaminghi/data-view-react';
import 'echarts-wordcloud/dist/echarts-wordcloud.min';
import React, { useEffect } from 'react';
import { useImmer } from 'use-immer';
import '../../Home.less';

const ColumnCharts: React.FC = () => {
  const [options, setOptions] = useImmer({
    series: [
      {
        type: 'wordCloud',
        gridSize: 1,
        sizeRange: [12, 50],
        rotationRange: [-90, 90],
        rotationStep: 45,
        shape: 'diamond',
        width: '100%',
        textPadding: 0,
        autoSize: {
          enable: true,
          minSize: 6,
        },
        textStyle: {
          normal: {
            textBorderColor: 'rgba(255,255,255,0.3)',
            textBorderWidth: 1,
            color: () => {
              return 'rgb(' + [Math.round(Math.random() * 160), Math.round(Math.random() * 160), Math.round(Math.random() * 160)].join(',') + ')';
            },
          },
          emphasis: {
            fontSize: 20,
          },
        },
        data: [
          {
            name: '区块链',
            value: 810,
          },
          {
            name: '云计算',
            value: 520,
          },
          {
            name: '人工智能',
            value: 928,
          },
          {
            name: '大数据',
            value: 906,
          },
          {
            name: '高考大数据',
            value: 514,
          },
          {
            name: '数据共享',
            value: 312,
          },
          {
            name: '关联分析',
            value: 941,
          },
          {
            name: '应用层',
            value: 358,
          },
          {
            name: '数据大屏',
            value: 194,
          },
          {
            name: '沙箱支付',
            value: 104,
          },
          {
            name: '高校大数据',
            value: 87,
          },
          {
            name: '相关志愿',
            value: 253,
          },
          {
            name: '可视化',
            value: 211,
          },
        ],
      },
    ],
    grid: {
      top: '1%',
      left: '2%',
      right: '2%',
      bottom: '0%',
      containLabel: true,
    },
    visualMap: {
      min: 0,
      max: 1000,
      inRange: {
        color: ['#5a9597', '#396993', '#c1fafd', '#94d8db', '#5a9597'],
      },
      textStyle: {
        color: '#333',
      },
      show: false,
    },
  });

  useEffect(() => {
    articleHomePage().then((res) => {
      setOptions((draft) => {
        draft.series[0].data = res.data.map((i: API.ChartsData) => {
          Number(i.value);
          return i;
        });
      });
    });
  }, []);

  return (
    <>
      <div className="marginb-10">
      <BorderBox7>
        <div className="echart_title">
          <div>我是标题</div>
        </div>
        <div className="h-min padding-5">
          <AutoChart option={options as any}></AutoChart>
        </div>
      </BorderBox7>
    </div>
      {/* <div className="chart7">
        <BorderBox4 color={['#396993', '#396993']}>
          <div className="chart_title">登录情况</div>
          <div className="chart_chart padding-5">
            <AutoChart option={options as any}></AutoChart>
          </div>
        </BorderBox4>
      </div> */}
    </>
  );
};
export default ColumnCharts;
